#pragma once
#include <QObject>
#include <qjsonvalue.h>
#include "FileTransferDef.h"

class FileReceiverServer;
class FileSender;
class FileTransfer : public QObject
{
    Q_OBJECT
public:
    explicit FileTransfer(QObject* parent = nullptr);
    ~FileTransfer();

public:
    void setSavePaths(const QList<FileTransferDef::sRevSavePath>& revSavePaths);
    bool start(int port);

    void sendFiles(const QString& ip, const QList<FileTransferDef::sFile>& files);
    void stop(const QString& ip);
    void stopAll ();

signals:
    void signalSendError(const QString& ip, const QString& error);
    void signalSendChanged(const QString& ip, const FileTransferDef::sFile& file);
    void signalSendFinished(const QString& ip, const FileTransferDef::sFile& file);
    void signalSendPrograss(const QString& ip, qreal percentage);
    void signalSendAllFinished(const QString& ip);
    void signalSendStop(const QString& ip);

    void signalReceiveProgressChanged(const QString& ip, int percentage);
    void signalFileReceiveFinished(const QString& ip, const QString& filePath, const QByteArray& userData);
    void signalReceiveStart(const QString& ip);
    void signalReceiveError(const QString& ip, FileTransferDef::eRecevieError);

private:
    FileReceiverServer* mReceiverServer = nullptr;
    QMap<QString, FileSender*> mIpAndSenderMap;
};